class Solution:
    def summaryRanges(self, nums):
        dic = []
        for num in nums:
            i = 0
            while i < len(dic):
                if num <= dic[i][0]:
                    break
                i = i + 1
            if i == 0:
                if len(dic) == 0:
                    dic.insert(0, [num, num])
                else:
                    if dic[0][0] - 1 == num:
                        dic[0][0] = num
                    else:
                        dic.insert(0, [num, num])
            elif i == len(dic):
                if dic[i - 1][1] + 1 == num:
                    dic[i - 1][1] = num
                else:
                    dic.append([num, num])
            else:
                if dic[i][0] - 1 == num:
                    dic[i][0] = num
                elif dic[i - 1][1] + 1 == num:
                    dic[i - 1][1] = num
                else:
                    dic.insert(i, [num, num])
            if i != 0 and i<len(dic):
                if dic[i][0] -1 == dic[i-1][1]:
                    dic[i - 1][1] = dic[i][1]
                    dic.pop(i)
        result = []
        for i in dic:
            if i[0] == i[1]:
                result.append(str(i[0]))
            else:
                result.append(str(i[0])+"->"+str(i[1]))
        return result


if __name__ == '__main__':
    so = Solution()
    s = [0,2,3,4,6,8,9]
    r = so.summaryRanges(s)
    print(r)
